package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.qxfw.common.entity.IssuerInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/3  星期一   15:42
 * @description : 此类用来 气象人员信息的底层数据接口
 ***************************************/

@Mapper
@DS("service")
public interface MeteorologicalPersonnelInformationManagementMapper extends BaseMapper<IssuerInfo> {

    @Select("select distinct permission from issuer_info")
    List<IssuerInfo> selectPermission();

    @Select("<script> " +
            "select id, username, phone, permission from issuer_info " +
            "where 1=1 " +
            "<if test='permission!=null'>and permission =#{permission}</if>" +
            "limit #{pageSize} OFFSET #{pageNo} </script>")
    List<IssuerInfo> selectByPermission(String permission,int pageNo,int pageSize);

    @Select("select username from issuer_info where username = #{userName}")
    List<IssuerInfo> selectByUserName(String userName);

    @Insert("insert into issuer_info(username, phone, permission) " +
            "values (#{userName},#{phone},#{permission})")
    Integer insertIssuerInfo(@Param("userName") String userName, @Param("phone") String phone, @Param("permission") String permission);

    @Select("select username from issuer_info where id = #{id}")
    List<IssuerInfo> selectById(int id);

    @Update("update issuer_info " +
            "set username = #{userName},password=#{password},phone=#{phone},permission=#{permission} " +
            "where id = #{id}")
    Integer updateIssuerInfo(@Param("id") int id, @Param("userName") String userName, @Param("password") String password, @Param("phone") String phone, @Param("permission") String permission);

    @Delete("delete from issuer_info where id = #{id}")
    Integer deleteIssuerInfo(int id);

    @Select("select id,username,password,phone,permission from issuer_info")
    List<IssuerInfo> selectAllIssuerInfo();
}
